POV-Ray : Newsgroups : povray.programming : math and trig question : Re: math and trig question Server Time
28 Jul 2024 16:24:16 EDT (-0400)
  Re: math and trig question  
From: Tor Olav Kristensen
Date: 4 Apr 2000 12:04:52
Message: <38EA1167.DC358C7B@online.no>
Mike Weber wrote:

> Tor,
>
> Thanks for your input.
> You POV code is similar to what I am doing. You are rotating only on the X
> and Y axis and not the Z where I rotate only on the X and Z axis and not the
> Y.  I'm  not familiar with the POV normalize instruction, but maybe I could
> learn something from that.

vnormalize multiplies the vector with a scalar
so that the length of the vector becomes equal
to 1.

This is done by choosing a scalar that is equal
to the reciprocal of the vectors current length.

I.e. if it is a 3D-vector:

1/sqrt(pow(Vector.x, 2) +
       pow(Vector.y, 2) +
       pow(Vector.z, 2))

Note that if Vector is a null-vector (e.g. <0, 0>
or <0, 0, 0>) then (in POV-Ray) vnormalize(Vector)
just leaves it as a null-vector.

While this expression would generate a warning
message if Vector is a null-vector (division
by zero):

1/(vlength(Vector))*Vector

If 3D-vectors were used, then my expression;

<acos(vnormalize((x + y)*Vector).x)*(Vector.y > 0 ? -1 : 1),
acos(vnormalize(Vector).z),
0>

could be written like this:

#if(Vector.y > 0)
  #local Sign = 1;
#else
  #local Sign = -1;
#end // if

<-Sign*acos(Vector.x/sqrt(pow(Vector.x, 2) +
                          pow(Vector.y, 2))),
acos(Vector.z/sqrt(pow(Vector.x, 2) +
                   pow(Vector.y, 2) +
                   pow(Vector.z, 2))),
0>

The last part could also be written like this

<-Sign*acos(Vector.x/vlength((x+y)*Vector)),
acos(Vector.z/vlength(Vector)),
0>

But with these two expressions one would have to
check if the x and y components were both zero.

> Tor Olav Kristensen <tto### [at] onlineno> wrote in message
> news:38E8C44E.81C7E687@online.no...
> ...
> > Wouldn't you have to accumulate up the rotations that is needed when
> > wandering from point to point in your spline?
> >
> Not sure what you mean by that??
>
> Mike

When using rotate in POV-Ray, the rotations is
always done around origo.

If you calculated this rotation relative to the
previous point (as is my understanding of your
description) and then applied the rotation relative
to origo, believe it would end up with a wrong
rotation relative to the previous point.

But if you take a copy of the object as it is
when it's rotated to the "last point" and then
applies the new rotations to make it point to
the "next point" then (I guess) it will become
right.

And my idea was that instead of making a copy of
the object as it was after it had last been copied,
you could just add together all the rotations that
had been done until the "last point" and then add
the new rotations to these rotations before
applying them to a copy of the object as it was
when created in your XZ-plane.

But again I don't know if my assumptions about
what you are really doing, is right. :)

...And maybe all my "believes" and theories
don't hold...

Tor Olav

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.